package hibernate;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * HouseAddition entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see hibernate.HouseAddition
 * @author MyEclipse Persistence Tools
 */

public class HouseAdditionDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(HouseAdditionDAO.class);
	// property constants
	public static final String POWER = "power";
	public static final String GAS = "gas";
	public static final String INTERNET = "internet";
	public static final String FURNITURE = "furniture";
	public static final String BATH = "bath";
	public static final String HEATING = "heating";
	public static final String KITCHEN = "kitchen";
	public static final String BED = "bed";
	public static final String PHONE = "phone";
	public static final String TELEVISION = "television";
	public static final String CATV = "catv";
	public static final String WASHER = "washer";
	public static final String GARAGE = "garage";
	public static final String ELEVATOR = "elevator";

	protected void initDao() {
		// do nothing
	}

	public void save(HouseAddition transientInstance) {
		log.debug("saving HouseAddition instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(HouseAddition persistentInstance) {
		log.debug("deleting HouseAddition instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public HouseAddition findById(java.lang.Integer id) {
		log.debug("getting HouseAddition instance with id: " + id);
		try {
			HouseAddition instance = (HouseAddition) getHibernateTemplate()
					.get("hibernate.HouseAddition", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(HouseAddition instance) {
		log.debug("finding HouseAddition instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding HouseAddition instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from HouseAddition as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByPower(Object power) {
		return findByProperty(POWER, power);
	}

	public List findByGas(Object gas) {
		return findByProperty(GAS, gas);
	}

	public List findByInternet(Object internet) {
		return findByProperty(INTERNET, internet);
	}

	public List findByFurniture(Object furniture) {
		return findByProperty(FURNITURE, furniture);
	}

	public List findByBath(Object bath) {
		return findByProperty(BATH, bath);
	}

	public List findByHeating(Object heating) {
		return findByProperty(HEATING, heating);
	}

	public List findByKitchen(Object kitchen) {
		return findByProperty(KITCHEN, kitchen);
	}

	public List findByBed(Object bed) {
		return findByProperty(BED, bed);
	}

	public List findByPhone(Object phone) {
		return findByProperty(PHONE, phone);
	}

	public List findByTelevision(Object television) {
		return findByProperty(TELEVISION, television);
	}

	public List findByCatv(Object catv) {
		return findByProperty(CATV, catv);
	}

	public List findByWasher(Object washer) {
		return findByProperty(WASHER, washer);
	}

	public List findByGarage(Object garage) {
		return findByProperty(GARAGE, garage);
	}

	public List findByElevator(Object elevator) {
		return findByProperty(ELEVATOR, elevator);
	}

	public List findAll() {
		log.debug("finding all HouseAddition instances");
		try {
			String queryString = "from HouseAddition";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public HouseAddition merge(HouseAddition detachedInstance) {
		log.debug("merging HouseAddition instance");
		try {
			HouseAddition result = (HouseAddition) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(HouseAddition instance) {
		log.debug("attaching dirty HouseAddition instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(HouseAddition instance) {
		log.debug("attaching clean HouseAddition instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static HouseAdditionDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (HouseAdditionDAO) ctx.getBean("HouseAdditionDAO");
	}
}